<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 
            graph[i]为每个节点可走到的节点，因此最后一个一定为空（有向无环图）
        
            输入：graph = [[1,2],[3],[3],[]]

            从0节点开始遍历，进入到了1，然后继续遍历1节点可以访问的路径
            */
            var allPathsSourceTarget = function (graph) {
                let path = [0]
                let res = []
                function dfs(path, start) {
                    if (start == graph.length - 1) {
                        return res.push([...path])
                    }
                    for (let i = 0; i < graph[start].length; i++) {
                        path.push(graph[start][i])
                        dfs(path, graph[start][i])
                        path.pop()
                    }
                }
                dfs(path, 0)
                return res
            }
        </script>
    </body>
</html>
